#include <windows.h> #include <stdio.h> #include <tchar.h> void _tmain( int argc, TCHAR *argv[] ) { STARTUPINFO si; PROCESS_INFORMATION pi; ZeroMemory( &si, sizeof(si) ); si.cb = sizeof(si); ZeroMemory( &pi, sizeof(pi) ); char *link = argv[0] ; LPTSTR szCmdline = _tcsdup(TEXT(link)); LPTSTR szParam ; int i = 0 ; if ( argc == 1 ){ strcat(link," 0") ; szParam = _tcsdup(TEXT(link)) ; } else { char buffer[100] ; i = atoi(argv[1]) + 1 ; itoa(i,buffer,10) ; strcat(link," ") ; strcat(link,buffer) ; szParam = _tcsdup(TEXT(link)) ; } if ( i < 10 ){ if( !CreateProcess(szCmdline,szParam,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi ) ) { printf( "CreateProcess failed (%d).\n", GetLastError() ); return; } printf("id = %d , output i = %d\n", GetCurrentProcessId() , i ); } WaitForSingleObject( pi.hProcess, INFINITE ); CloseHandle( pi.hProcess ); CloseHandle( pi.hThread ); }
|